package com.gec.service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.gec.dao.DeptMapper;
import com.gec.domain.Dept;
import com.gec.domain.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author Aniki
 * @date  2021-12-15
 */
@Service
public class DeptServiceImpl  implements DeptService {
    @Autowired
    private DeptMapper deptMapper;

    @Override
    public PageBean<Dept> getDeptList(int page, int limit, Map data) {
      /*  //后面做模糊搜索计算偏移量
        int offset = (page - 1) * limit;
        List<Dept> list = null;
        //data存入的是模糊搜索关键字数据
        list = deptMapper.queryDeptList(data,offset,page);

        PageBean pBean = new PageBean();
        *//**临时写法 后面要改*//*
        pBean.setCount(list.size());
        pBean.setList(list);
        System.out.println( list );
        return pBean;*/
        /**开启分页： TRUE 获取记录数   PageHelper会拦截查找内容 */
        Page<Dept> pages = PageHelper.startPage(page, limit, true);
        /**获取到列表*/
        List<Dept> list = deptMapper.queryDeptList(data);
        PageBean<Dept> pageBean = new PageBean();
        /**封装分页Page*/
        int count = (int)pages.getTotal();
        pageBean.setCount(count);
        pageBean.setList(list);
        return pageBean;
    }

    @Override
    public void delDept(String id) {
        deptMapper.delDept(id);
    }

    @Override
    public void saveDept(Dept dept) {
        deptMapper.saveDept(dept);
    }

    @Override
    public void updateDept(Dept dept) {
        deptMapper.updateDept(dept);
    }

    @Override
    public Dept getDept(String id) {

        return deptMapper.getDept(id);
    }
}
